<template>
  <div class="department">
    <page-search
      :searchFormConfig="searchFormConfig"
      @searchBtnClick="hanldeSearchBtnClick"
      @resetBtnClick="hanldeResetBtnClick"
    ></page-search>
    <page-content
      ref="pageContentRef"
      pageName="department"
      :contentTableConfig="contentTableConfig"
      @newBtnClick="handleNewData"
      @handleEditorRow="handleEditorRow"
    ></page-content>
    <page-modal
      ref="pageModalRef"
      pageName="department"
      :modalInfo="modalInfo"
      :modalConfig="modalConfigRef"
    ></page-modal>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, computed, watchEffect } from "vue";
import { useStore } from "@/store";

import { usePageSearch } from "@/hooks/usePageSearch";
import { usePageModal } from "@/hooks/usePageModal";

import PageSearch from "@/components/page-search";
import pageContent from "@/components/page-content";
import PageModal from "@/components/page-modal";

import { searchFormConfig } from "./config/search.config";
import { contentTableConfig } from "./config/content.config";
import { modalConfig } from "./config/modal-config";

export default defineComponent({
  components: {
    PageSearch,
    pageContent,
    PageModal,
  },
  setup() {
    const store = useStore();
    const { pageContentRef, hanldeSearchBtnClick, hanldeResetBtnClick } =
      usePageSearch();
    const { modalInfo, pageModalRef, handleNewData, handleEditorRow } =
      usePageModal();
    // 设置部门
    const modalConfigRef = computed(() => {
      const departmentOption = modalConfig.formItems.find((item) => {
        return item.field === "parentId";
      });
      departmentOption!.options = store.state.systemModule.departmentList.map(
        (item) => {
          return { label: item.name, value: item.id };
        }
      );
      return modalConfig;
    });

    return {
      searchFormConfig,
      pageContentRef,
      contentTableConfig,
      hanldeSearchBtnClick,
      hanldeResetBtnClick,
      modalConfigRef,
      modalConfig,
      modalInfo,
      pageModalRef,
      handleNewData,
      handleEditorRow,
    };
  },
});
</script>
